/**
 * 
 */
package com.oron3.bouncer.objects.shapes;




/**
 * @author Ofek
 *
 */
public class Sphere implements Shape {
	public float angle;
	public float r;
	public Point center;
	public static final int RELATION_ON= 0;
	public static final int RELATION_OUTSIDE = 1;
	public static final int RELATION_INSIDE = 2;
	public static final int RELATION_PART_IN_PART_OUT = 3;
	private static final float TOLERANCE = 0.000001f;


	/**
	 * @param x
	 * @param y
	 * @param z
	 * @param radius
	 * @param f
	 */
	public Sphere(final float x, final float y, final float z, final float radius) {
		center = new Point(x,y,z);
		r = radius;
	}


	/**
	 * @param project
	 * @param i
	 * @param d
	 */
	public Sphere(final Point center, final float r) {
		this(center.x,center.y,center.z,r);
	}




	public void rotate(final float angle) {
		this.angle = angle;
	}









	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.GLObject#intersects(com.oron3.bouncer.objects.GLObject)
	 */
	@Override
	public boolean intersects(final Shape s) {
		if ( s instanceof LineSegment ) return s.intersects(this);
		if ( s instanceof Cylinder ) return s.intersects(this);
		if ( s instanceof Rectangle ) return s.intersects(this);
		throw new UnsupportedOperationException();
	}


	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.shapes.Shape#intersection(com.oron3.bouncer.objects.shapes.Shape)
	 */
	@Override
	public Intersection intersection(final Shape o) {
		return null;
	}


	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.shapes.Shape#calcRelation(com.oron3.bouncer.objects.shapes.Shape)
	 */
	@Override
	public int describeRelation(final Shape o) {
		if (o instanceof Point) {
			final Point p = (Point) o;
			final float dFromCenter = new Vector(p.sub(center)).length();
			if (Math.abs(dFromCenter-r) <= TOLERANCE) return RELATION_ON;
			if (dFromCenter<r) return RELATION_INSIDE;
			return RELATION_OUTSIDE;

		} throw new IllegalArgumentException();
	}


	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.shapes.Shape#isInside(com.oron3.bouncer.objects.shapes.Shape)
	 */
	@Override
	public boolean isInside(final Shape o) {
		final int describeRelation = describeRelation(o);
		return describeRelation==RELATION_ON || describeRelation==RELATION_INSIDE;
	}


	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.shapes.Shape#project(com.oron3.bouncer.objects.shapes.Shape)
	 */
	@Override
	public Shape project(final Shape o) {
		throw new IllegalArgumentException();
	}





}
